package com.yxx.community.dto;

import com.yxx.community.exception.CustomizeErrorCode;
import com.yxx.community.exception.CustomizeException;
import lombok.Data;

/**
 * @Author: YuXinXin
 * @Description:
 * @Date:Created in 20:22 2020/2/6
 **/
@Data
public class ResultDTO<T> {
  private Integer code;
  private String message;
  private T data;

  public static ResultDTO okof(){
    ResultDTO resultDTO = new ResultDTO();
    resultDTO.setCode(200);
    resultDTO.setMessage("请求成功");
    return resultDTO;
  }
  public static <T> ResultDTO  okof(T t){
    ResultDTO resultDTO = new ResultDTO();
    resultDTO.setCode(200);
    resultDTO.setMessage("请求成功");
    resultDTO.setData(t);
    return resultDTO;
  }

  public static ResultDTO errorof(Integer code,String message){
    ResultDTO resultDTO = new ResultDTO();
    resultDTO.setCode(code);
    resultDTO.setMessage(message);
    return resultDTO;
  }

  public static ResultDTO errorof(CustomizeErrorCode errorCode) {
    return errorof(errorCode.getCode(),errorCode.getMessage());
  }

  public static ResultDTO errorof(CustomizeException e) {
    return errorof(e.getCode(),e.getMessage());
  }
}
